package com.wanwu.channel.converter;

import com.alibaba.fastjson.JSON;
import com.wanwu.channel.common.util.DateUtils;
import com.wanwu.channel.facade.dto.resp.ChPayQueryRespDto;
import com.wanwu.channel.dao.entity.ChannelPayEntity;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;

/**
 * @author zhy
 * @date 2020-1-7
 * @descrption 自定义转换器
 */
public class Converter {

    /**
     * 处理订单查询返回结果
     *
     * @param channelPay
     * @return
     */
    public static ChPayQueryRespDto buildPayQuryRespVo(ChannelPayEntity channelPay) {
        ChPayQueryRespDto resp = new ChPayQueryRespDto();
        resp.setChannelNo(channelPay.getChannelNo());
        resp.setThirdErrCode(channelPay.getErrorCode());
        resp.setThirdErrMsg(channelPay.getErrorMsg());
        resp.setBizOrderNo(channelPay.getBizOrderNo());
        resp.setBizCode(channelPay.getBizCode());
        resp.setStatus(channelPay.getPayStatus() + "");
        resp.setThirdOrderNo(channelPay.getThirdOrderNo());
        resp.setTlOrderNo(channelPay.getTlOrderNo());
        resp.setFinishTime(DateUtils.get(1, channelPay.getPayTime()));
        if(!StringUtils.isEmpty(channelPay.getNotifyData())){
            String fee = JSON.parseObject(channelPay.getNotifyData()).getString("fee");
            if(!StringUtils.isEmpty(fee)){
                resp.setFeeAmount(new BigDecimal(fee));
            }
        }else{
            resp.setFeeAmount(BigDecimal.ZERO);
        }
        return resp;
    }
}
